# -*- encoding=utf8 -*-
__author__ = "Bryan.Chen"

from airtest.core.api import *

auto_setup(__file__)

from poco.drivers.std import StdPoco
poco = StdPoco()

using("../FlowTest.air")
import FlowTest


class MahjongTransferThree(FlowTest.BaseTestCase):

    def __init__(self):
        print("%s __init__" % (__file__))
    
    def runTest(self, args):

        isTimeOut = False
        t1 = time.time()
        tableScene = poco("TableScene")
        while not tableScene.exists():
            tableScene = poco("TableScene")
            if time.time() - t1 > 5 * 60:
                isTimeOut = True
                break

        if isTimeOut:
            return False
        try:    
            poco("HuanSanZhangLayer").wait_for_appearance()
        except:
            print("开局超时")
            return False
        
        hszLayer = poco("HuanSanZhangLayer")
        
        myHandcard = poco("MyHandCardLayer").child("Layer").child("hcard_node1")

        isTimeOut = False
        t1 = time.time()
        myCardLen = 0
        while True:
            myCardItems = myHandcard.children()
            myCardLen = len(myCardItems)
            if myCardLen > 0:
                break
            if time.time() - t1 > 5 * 60:
                isTimeOut = True
                break
                
        if isTimeOut:
            btnExit = poco("exit_btn")
            if btnExit.exists():
                btnExit.click([0.5, 0.5])
                poco("TipsLobbyLayer").wait_for_appearance()
                btnOK = poco("TipsLobbyLayer").offspring("ok_btn_2")
                if btnOK.exists():
                    btnOK.click([0.5, 0.5])
                    isTimeOut = False
            return True
                
        assert_equal(myCardLen == 13 or myCardLen == 14, True, "手牌数量正常")
        
        btnHszOK = hszLayer.offspring("btn_hsz_ok")
        btnHszOK.click([0.5, 0.5])

        return True
                       
_instance = MahjongTransferThree()
runTest = _instance.runTest
    

